package com.woniuxy.carrental.service.impl;

import com.woniuxy.carrental.entity.Parking;
import com.woniuxy.carrental.entity.RentCarInfo;
import com.woniuxy.carrental.mapper.ParkingMapper;
import com.woniuxy.carrental.mapper.RentCarInfoMapper;
import com.woniuxy.carrental.service.ParkingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author author
 * @create 2021-10-10 22:42
 */
@Service
public class ParkingServiceImpl implements ParkingService {

    @Autowired
    ParkingMapper parkingMapper;

    @Autowired
    RentCarInfoMapper rentCarInfoMapper;

    @Override
    public void addParking(Parking parking) {
//     parking.setContent("<img src='\"+require('@/images/car.png')+\"' />");
        parking.setPhoto("<img src='../images/car.png')' />");
        parking.setParkcarnumber(0);

     parkingMapper.addParking(parking);
    }

    @Override
    public List<Parking> getParking() {


        return parkingMapper.getParking();
    }

    @Override
    public void updateParking(Parking parking) {
       parkingMapper.updateParking(parking);
    }

    @Override
    public List<Parking> selectAllParking(Parking parking, Integer pageIndex, Integer pageSize) {
        List<Parking> parkings = parkingMapper.selectAllParking(parking, pageIndex, pageSize);
        return parkings;
    }

    @Override
    public int selectParkingCountBylimit(Parking parking) {
        return parkingMapper.selectParkingCountBylimit(parking);
    }

    @Override
    public void delectParkingByid(int parkid) {
      parkingMapper.delectParkingByid(parkid);
    }

    @Override
    public List<RentCarInfo> getRentCarInfobyparkid(int parkid) {
        return parkingMapper.getRentCarInfobyparkid(parkid);
    }

    @Override
    public void updateStareParking(int parkid) {
        parkingMapper.updateStareParking(parkid);
    }

    @Override
    public List<RentCarInfo> selectRentCarInfoByPid(String lonlat) {
        String lon =lonlat.substring(0, 6);
        Parking parking = parkingMapper.selectnumberBylonlan(lon);

        RentCarInfo rentCarInfo=new RentCarInfo();
        if(parking!=null){
            int parkid=parking.getParkid();
            rentCarInfo.setParkid(parkid);
            List<RentCarInfo> rentCarInfos = rentCarInfoMapper.selectAllRentCarInfo(rentCarInfo, 1, 50);
            return rentCarInfos ;
        }else{
            return null;
        }

    }
}
